package live.cz.dao;

import java.util.Date;
import java.util.Map;
import java.util.TreeMap;

import live.common.Format;
import live.common.PostParam;
import live.cz.entity.Order;
import live.response.WebServicePay;

public class OrderPay {
	public String goPay(Order order,String memberNo) throws Exception{
		WebServicePay wsp = new WebServicePay();
		Map tm = new TreeMap();
		//交易代码
		tm.put("service_id", "110003");
		//发起方机构编码
		tm.put("req_org_cd", "123456");
		//发起时间
		tm.put("req_trans_tm", Format.getInstance().dateFormatString(new Date(), "yyyyMMddHHmmss"));
		//订单号
		tm.put("req_trans_seq", new Date().getTime());
		tm.put("order_id", order.getOrderid());
		tm.put("seller_id", "12345");
		tm.put("sub_order_flag", "N");
		tm.put("sub_order_num", "0");
		tm.put("sub_order_dtl", "");
		tm.put("order_desc", returnOrderDesc(order));
		tm.put("tot_trans_amt", returnPrice(order.getSalePrice()));
		tm.put("buyer_id", "12345678");
		tm.put("valid_date", 0);
		tm.put("notify_url", "http://192.168.100.10:8080/notice.do");
		tm.put("return_url", "");
		tm.put("original_service_id", "");
		tm.put("original_req_org_cd", "");
		tm.put("original_req_trans_seq", "");
		tm.put("original_order_id", "");
		tm.put("sign", "");
		tm.put("sign_type", "MD5");
		//return null;
		return wsp.pixNull(PostParam.PAY_API.toString(), tm);
	}
	
	public String returnOrderDtl(Order order){
		String sso_id="12345";
		String result=new StringBuffer(sso_id).append("^")
		.append(order.getOrderid()).append("^")
		.append(order.getProdInfo()).append(order.getProPrice())
		.append("元充值[").append(order.getPhonenum()).append("]")
		.append(order.getSalePrice()*100).toString();
		return result;
	}
	
	public String returnOrderDesc(Order order){
		String result=new StringBuffer(order.getProdInfo()).append(order.getProPrice())
		.append("元充值[").append(order.getPhonenum()).append("]")
		.append(returnPrice(order.getSalePrice())).toString();
		return result;
	}
	
	public int returnPrice(double num){
		return (int)(num*100);
	}
}
